#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>



typedef void (*sighandler_t)(int);

void ehco_hello(int signum)
{
    printf("\n收到%d信号,停止程序!\n",signum);
    exit(signum);
}

int main()
{
    sighandler_t result = signal(SIGINT,ehco_hello);
    /*
    RETURN VALUE
       signal()  returns  the previous value of the signal handler, or SIG_ERR
       on error.  In the event of an error,  errno  is  set  to  indicate  the
       cause.
    */
    if (result == SIG_ERR)
    {
        perror("signal");
        return 1;
    }

    while (1)
    {
        printf("hello\n");
        sleep(1);
    }
    
    

    return 0;
}